package com.beehoo.dcportal.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class FileBean implements Serializable {

	private static final long serialVersionUID = -1437086588577618594L;

	/***********单个文件上传用到的字段************/
	private File file;
	private String contentType;
	private String fileName;
	private int fileSize;
	/***********多文件上传用到的字段************/
	private List<Integer> uploadFileSizeList = new ArrayList<Integer>();
	private List<File> uploads = new ArrayList<File>();
	private List<String> uploadFileNames = new ArrayList<String>();
	private List<String> uploadContentTypes = new ArrayList<String>();

	public List<File> getUpload() {
		return this.uploads;
	}

	public void setUpload(List<File> uploads) {
		this.uploads = uploads;
	}

	public List<String> getUploadFileName() {
		return this.uploadFileNames;
	}

	public void setUploadFileName(List<String> uploadFileNames) {
		this.uploadFileNames = uploadFileNames;
	}

	public List<String> getUploadContentType() {
		return this.uploadContentTypes;
	}

	public void setUploadContentType(List<String> contentTypes) {
		this.uploadContentTypes = contentTypes;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public void setFileContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getContentType() {
		return contentType;
	}

	public void setFileFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileName() {
		return fileName;
	}

	public int getFileSize() {
		try {
			this.fileSize = new FileInputStream(this.file).available();
		} catch (FileNotFoundException e) {
			this.fileSize = 0;
		} catch (IOException e) {
			this.fileSize = 0;
		}
		return fileSize;
	}

	public void setFileFileSize(int fileSize) {
		this.fileSize = fileSize;
	}

	public List<Integer> getUploadFileSizeList() {
		Integer size = null;
		for (File file : this.uploads) {
			try {
				size = new FileInputStream(file).available();
			} catch (FileNotFoundException e) {
				size = 0;
			} catch (IOException e) {
				size = 0;
			}
			uploadFileSizeList.add(size);
		}
		return uploadFileSizeList;
	}
}
